<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let obj = {
            '公寓': [],
            '别墅': []
        }
        const arr = ["中华园,北京市,公寓", "华景苑,上海市,别墅", "新城市广场,深圳市,公寓", "雅居乐花园,广州市,别墅", "恒大城,广州市,公寓", "太阳花园,北京市,别墅"];
        arr.forEach(e => {
            // console.log(e)
            let x = e.indexOf('公寓')
            if (x === -1) {
                // console.log(e);
                e = e.toString()
                let a = e.split(',')
                obj['公寓'].push(a[0])
            } else {
                e = e.toString()
                let b = e.split(',')
                obj['别墅'].push(b[0])
            }
        })
        console.log(obj)
    </script>
</body>

</html>